package com.cwf.admin.web.controller.system;


import com.cwf.common.entity.http.R;
import com.cwf.framework.authcode.service.KaptchaService;
import com.cwf.security.dao.UserLoginDao;
import com.cwf.security.entity.UserLogin;
import com.cwf.security.service.UserLoginService;
import com.cwf.security.validation.login.UserLoginRequestParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/admin")
@Valid
public class LoginController {


    @Autowired
    UserLoginService userLoginService;


    @Autowired
    KaptchaService kaptchaService;


    @Autowired
    UserLoginDao userLoginDao;

    @PostMapping("/login")
    public R login(@RequestBody @Validated UserLoginRequestParam userLogin){

        //检查验证码
        kaptchaService.checkImageCode(userLogin.getUuid(),userLogin.getCode());



        UserLogin userInfo = UserLogin.builder()
                .userName(userLogin.getUserName())
                .password(userLogin.getPassword())
                .build();

        String token = userLoginService.login(userInfo);





        return R.success(token);




    }
}
